package com.zjitc.pigspring.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zjitc.pigspring.bean.po.Collect;
import com.zjitc.pigspring.bean.po.CollectVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface CollectMapper extends BaseMapper<Collect> {

    @Select("select u.name as username,c.user_id as userId,g.seller_id as sellerId,c.good_id as goodId,c.id as id,g.img as img,g.`name` as goodName,g.price as price,s.name as sellerName from" +
            " collect as c left join goods as g on c.good_id = g.id " +
            "left join seller as s on g.seller_id = s.id left join user as u on c.user_id = u.id")
    List<CollectVO> getAll();

    @Select("select c.id as id,g.img as img,g.`name` as goodName,g.price as price,s.name as sellerName from" +
            " collect as c left join goods as g on c.good_id = g.id " +
            "left join seller as s on g.seller_id = s.id where c.user_id = #{id};")
    List<CollectVO> getByUser(Integer id);

    @Select("select u.name as username,c.user_id as userId,g.seller_id as sellerId,c.good_id as goodId,c.id as id,g.img as img,g.`name` as goodName,g.price as price,s.name as sellerName from" +
            " collect as c left join goods as g on c.good_id = g.id " +
            "left join seller as s on g.seller_id = s.id left join user as u on c.user_id = u.id where u.name LIKE CONCAT('%', #{username}, '%')")
    List<CollectVO> getListByUsername(CollectVO collect);

    @Delete("delete from collect where good_id = #{id}")
    boolean deleteByGoodId(Integer id);

    @Delete("delete from collect where user_id = #{id}")
    boolean deleteByUserId(Integer id);
}
